package com.fh.Advice;

import java.util.Iterator;
import java.util.Map;

/**
 * Created by dell、 on 2017/12/18.
 */
public class LinkedHashMap<K,V> extends java.util.LinkedHashMap<K,V> {
    @Override
    public String toString() {
        Iterator<Map.Entry<K,V>> i = entrySet().iterator();
        if (! i.hasNext())
            return "{}";

        StringBuilder sb = new StringBuilder();
        sb.append('{');
        for (;;) {
            Map.Entry<K,V> e = i.next();
            K key = e.getKey();
            V value = e.getValue();
            sb.append(key   == this ? "(this Map)" :"\"" +key+"\"");
            sb.append(':');
            sb.append(value == this ? "(this Map)" :"\"" + value+"\"");
            if (! i.hasNext())
                return sb.append('}').toString();
            sb.append(',').append(' ');
        }
    }
}
